//
//  GHOrderFooterView.m
//  GodHorses
//
//  Created by Mac on 2017/11/20.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLOrderFooterView.h"
@interface KLOrderFooterView()
@property(nonatomic, strong) STLabel                     *payLable;//应付款
@property(nonatomic, strong) STLabel                     *timeLable;//
@property(nonatomic, strong) STLabel                     *orderLable;//

@property(nonatomic, strong) STLabel                     *peopleLable;//地址
@property(nonatomic, strong) STLabel                     *phoneLable;//电话号码
@property(nonatomic, strong) STLabel                     *addLable;//地址
@end
@implementation KLOrderFooterView

+ (CGFloat)footerHeight{
    return 160 + 10 + 40 +30  +20;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithReuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, [KLOrderFooterView footerHeight] - 10)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    self.payLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 40)
                                              text:@"共两件商品,应付款 3600"
                                         textColor:KL_redColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.payLable];
    
    self.timeLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.payLable.st_bottom, UIScreenWidth - 20, 40)
                                              text:@"可用余额：20：00"
                                         textColor:KL_secendTextColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.timeLable];
    
    self.orderLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.timeLable.st_bottom, UIScreenWidth - 20, 40)
                                                 text:@"可用积分：100"
                                            textColor:KL_secendTextColor
                                                 font:14
                                          isSizetoFit:NO
                                        textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.orderLable];
    
    
    self.peopleLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.orderLable.st_bottom, UIScreenWidth - 20, 20)
                                                text:@"可用积分：100"
                                           textColor:KL_secendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.peopleLable];
    
    self.phoneLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.peopleLable.st_bottom, UIScreenWidth - 20, 20)
                                              text:@"可用积分：100"
                                         textColor:KL_secendTextColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.phoneLable];
    
    
    self.addLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.phoneLable.st_bottom, UIScreenWidth - 20, 20)
                                                text:@"可用积分：100"
                                           textColor:KL_secendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.addLable];

    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, self.addLable.bottom + 10, UIScreenWidth - 20, 0.5)];
    line.backgroundColor = KL_lineColor;
    [whiteView addSubview:line];
    
    self.confimButton = [[STButton alloc] initWithFrame:CGRectMake(0,line.st_bottom+10, 80, 30)
                                                     title:@"付款"
                                                titleColor:KL_YellowBackGroundColor
                                                 titleFont:13
                                              cornerRadius:8
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:nil];
    self.confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.confimButton.st_right = UIScreenWidth - 10;
    [self.confimButton st_setBorderWith:1 borderColor:KL_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.confimButton];
    
}
- (NSString*)defultTitle{
    NSLog(@"订单状态%@",_model.state);
    switch (_model.state.integerValue) {
        case 0:
            return @"";
            break;
        case 1:
            return @"付款";
            break;
        case 2:
            return @"待发货";
            break;
        case 3:
            return @"确认收货";
            break;
        case 4:
            return @"已完成";
            break;
        default:
            break;
    }
    return @"";
}
- (void)setModel:(BLOrderModel *)model{
    _model = model;
    NSString * title = [self defultTitle];
    [self.confimButton setTitle:title forState:UIControlStateNormal];
    self.confimButton.hidden = !self.confimButton.currentTitle.length;
    
    NSInteger num = 0;
    CGFloat price = 0;
    for (BLGoodModel * good in model.goods) {
        num = num + good.num.integerValue;
        price = price + good.num.integerValue * good.price.floatValue;
    }
    
    NSString * paySting = @"应";
    if (model.state.integerValue == 1) {
        paySting = @"应";
    }else{
        paySting = @"已";
    }
//    for (BLGoodModel * goodModel in model.goods) {
//
//    }
    if (model.make_score.integerValue > 0) {
        //积分 + 钱
       self.payLable.text = [NSString stringWithFormat:@"共%ld件商品,%@付款%@+%@ 积分",
                             model.num.integerValue,paySting,
                             [self allMoney],
                             [self allpoint]];
        if ([model.goods_type isEqualToString:@"3"]) {
            //积分
            self.payLable.text = [NSString stringWithFormat:@"共%ld件商品,%@付款%@ 积分",
                                  model.num.integerValue,
                                  paySting,
                                  [self allpoint]];
        }
        
        
    }else{
        NSString *grade = @"";
        if (model.make_grade.integerValue > 0) {
            grade = [NSString stringWithFormat:@"+赠送盖币%@",
                        [self allGrade]];
        }
        self.payLable.text = [NSString stringWithFormat:@"共%ld件商品,%@付款%@%@元",
                              model.num.integerValue,paySting,[self allMoney],grade];
    }
    
    
    
    self.timeLable.text = [NSString stringWithFormat:@"创建时间:%@",model.create_time];
    
    self.orderLable.text = [NSString stringWithFormat:@"订单编号:%@",model.oder_nu];
    
    self.peopleLable.text = [NSString stringWithFormat:@"收件人:%@",model.people];
    self.phoneLable.text = [NSString stringWithFormat:@"联系电话:%@",model.mobile];
    self.addLable.text = [NSString stringWithFormat:@"地址详情:%@",model.address];
    
}
- (NSString*)allGrade{
    CGFloat grade = 0;
    for (BLGoodModel * model in self.model.goods) {
        grade = grade +  model.num.integerValue * model.grade.floatValue;
    }
    return @(grade).description;
}
- (NSString*)allMoney{
    CGFloat money = 0;
    for (BLGoodModel * model in self.model.goods) {
        money = money +  model.num.integerValue * model.money.floatValue;
    }
    return @(money).description;
}
- (NSString*)allpoint{
    CGFloat point = 0;
    for (BLGoodModel * model in self.model.goods) {
        point = point +  model.num.integerValue * model.score.floatValue;
    }
    return @(point).description;
}
@end

